// import Cookies from 'js-cookie'

import { storage } from './Storage'
import type { LocaleType } from '@/locales/config'

const { VITE_APP_BASE_TOKEN, VITE_APP_BASE_USERINFO } = import.meta.env

const TokenKey = VITE_APP_BASE_TOKEN
const UserInfo = VITE_APP_BASE_USERINFO
const MenuKey = 'menus'
const SidebarKey = 'sidebarStatus'
const LocaleKey = 'locale'

export function getToken() {
  return storage.getCookie(TokenKey as string)
}

export function setToken(token: string) {
  return storage.setCookie(TokenKey as string, token)
}

export function removeToken() {
  return storage.removeCookie(TokenKey as string)
}

export function getUserinfo() {
  return storage.get(UserInfo as string)
}

export function setUserinfo(info: Object) {
  return storage.set(UserInfo as string, info)
}

export function removeUserinfo() {
  return storage.remove(UserInfo as string)
}

export function setMenu(menu: any) {
  return storage.set(MenuKey, menu)
}

export function getMenu() {
  return storage.get(MenuKey)
}

export function removeMenu() {
  return storage.remove(MenuKey)
}

export function getSidebarStatus() {
  return storage.get(SidebarKey as string)
}

export function setSidebarStatus(status: string) {
  return storage.set(SidebarKey as string, status, null)
}

export function setLocale(locale: LocaleType) {
  return storage.set(LocaleKey, locale, null)
}

export function getLocale() {
  return storage.get(LocaleKey)
}

export function removeLocale() {
  return storage.remove(LocaleKey)
}

export function removeAll() {
  removeToken()
  removeUserinfo()
  removeMenu()
}
